﻿
@{
    ViewBag.Title = "流程管理";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style type="text/css">
    .form .formValue input.form-control {
        height: 32px;
        line-height: 32px;
        padding: 0px;
        resize: none;
        border-radius: 0px;
        box-shadow: none;
        text-indent: 5px
    }

    .textValue {
        width: 100%;
    }

    .selectbox {
        color: #444;
        line-height: 34px;
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        height: 34px;
        width: 100%;
    }

    .search {
        margin-left: 10px;
        padding: 0px;
    }

    table td {
        height: 40px;
        line-height: 40px;
    }

    .zdyPanel {
        background-color: #fff;
        border-top: 1px solid #ddd;
        border-left: 1px solid #ddd;
        border-right: 1px solid #ddd;
        margin: 0px;
        float: left;
        width: 100%;
    }

    .zdyTool {
        float: left;
        padding-left: 10px;
        width: 100%;
    }

    .zdyBar {
        padding: 0px;
        margin: 0px;
        margin-top: 3px;
    }

    .zdyUL {
        list-style-type: none;
        margin: 5px 0px 0px -3px;
        padding: 0px;
    }

        .zdyUL li {
            float: left;
            list-style: none;
            height: 24px;
            line-height: 22px;
        }

            .zdyUL li a {
                cursor: pointer;
                padding: 5px 10px;
                border-radius: 4px;
            }

            .zdyUL li i {
                margin-right: 4px;
                font-size: 13px;
                color: #666;
                vertical-align: middle;
                margin-top: -1px;
            }

            .zdyUL li a:hover {
                text-decoration: none;
                background-color: #1ABC9C;
                color: #fff;
            }

    .zdyGirdPanel {
        width: 100%;
        margin: 0px;
        padding: 0px;
        float: left;
    }

    .zdyContentPanel {
        width: 100%;
        margin: 5px 0px 0px 0px;
        padding: 0px;
        float: left;
    }

    .zdyFont {
        padding-left: 5px;
        color: #ff6a00;
    }

    .autocomplete-suggestions {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        border: 1px solid #999;
        background: #FFF;
        cursor: default;
        overflow: auto;
        -webkit-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        -moz-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-no-suggestion {
        padding: 2px 5px;
    }

    .zdyUL {
        list-style-type: none;
        margin: 5px 0px 0px -3px;
        padding: 0px;
    }

        .zdyUL li {
            float: left;
            list-style: none;
            height: 24px;
            line-height: 22px;
        }

            .zdyUL li a {
                cursor: pointer;
                padding: 5px 10px;
                border-radius: 4px;
            }

            .zdyUL li i {
                margin-right: 4px;
                font-size: 13px;
                color: #666;
                vertical-align: middle;
                margin-top: -1px;
            }

            .zdyUL li a:hover {
                text-decoration: none;
                background-color: #1ABC9C;
                color: #fff;
            }

    .zdyGirdPanel {
        padding-top: 3px;
    }

    .form .formValue {
        padding: 1px 3px;
    }
</style>
<script>
    $(function () {
        $("#state_horizon a.btn-default").click(function () {
            $("#state_horizon a.btn-default").removeClass("active");
            $(this).addClass("active");
            $('#btn_search').trigger("click");
        });
        GetItems();
        gridList();
    });

    function GetItems() {
        $.ajax({
            url: "/ClientManager/DemandInfos/GetItems",
            dataType: "json",
            async: false,
            success: function (data) {
                resultData = data;
                InitControl();
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
    }

    function InitControl() {
        var F_CityId = resultData.F_ActivityCityId;
        for (var i = 0; i < F_CityId.length; i++) {
            $("#F_CityId").append("<option value='" + F_CityId[i].F_ItemCode + "'>" + F_CityId[i].F_ItemName + "</option>");
        }

        var F_ActivityType = resultData.F_ActivityType;
        for (var i = 0; i < F_ActivityType.length; i++) {
            $("#F_ActivityType").append("<option value='" + F_ActivityType[i].F_ItemCode + "'>" + F_ActivityType[i].F_ItemName + "</option>");
        }
    }

    //public string F_Id { get; set; }

    //public string F_WorkFlowName { get; set; }

    //public DateTime? F_CreatorTime { get; set; }

    //public string F_Creator { get; set; }

    //public string F_WorkFlowDetailCount { get; set; }

    function gridList() {
        var $gridList = $("#gridList");
        var queryJson = {};
        $gridList.dataGrid({
            url: "/WorkFlowSetting/FlowManage/GetIndexGridJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: 630,
            colModel: [
                {
                    label: '流程名称', name: 'F_WorkFlowName', width: 150
                },
                {
                    label: '创建时间', name: 'F_CreatorTime', width: 150
                },
                {
                    label: '创建人', name: 'F_Creator', align: 'left', width: 130
                },
                {
                    label: '流转步骤', name: 'F_WorkFlowDetailCount', align: 'left', width: 120, formatter: function (cellvalue) {
                        return cellvalue + '个';
                    }
                },
                {
                    label: '操作', name: 'F_Id', width: 320, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        return '<div class="btn-group btn-group-xs" style="margin-top:5px;">'
                            //+ '   <button type="button" class="btn btn-info" onclick="btn_detail(\'' + cellvalue + '\', 0)">编辑步骤</button>'
                            + '   <button type="button" class="btn btn-info" onclick="btn_detail(\'' + cellvalue + '\', 0)">编辑流程步骤</button>'
                            + '   <button type="button" class="btn btn-danger" onclick="btn_detele(\'' + cellvalue + '\')">删除</button>'
                            + '</div>';
                    }
                },
                { label: '', name: 'F_Id', hidden: true }
            ],
            pager: "#gridPager",
            viewrecords: true,
            multiselect: false,
            sortname: 'F_Id',
            ondblClickRow: function (rowid, iRow, iCol, e) {
                var rowobj = $("#gridList").jqGridRowValue();
                if (rowobj["F_OrderState"] == 0 || rowobj["F_OrderState"] == -1) {
                    btn_Update();
                } else {
                    Detail();
                }
            },
            loadComplete: function (data) {

            }
        });
    }
    //$.modalConfirm

    function btn_detele(id) {
        $.modalConfirm('确定删除吗？', function (flag) {
            if (flag) {
                $.submitForm({
                    url: "/WorkFlowSetting/FlowManage/DeteleWorkFlow?keyValue=" + id,
                    param: {},
                    success: function (data) {
                        $.currentWindow().$("#gridList").trigger("reloadGrid");
                    }
                });
            }
        });
    }

    function Detail() {
        var rowobj = $("#gridList").jqGridRowValue();
        if (rowobj.F_Id) {
            $.modalOpen({
                id: "editForm",
                title: "编辑流程管理模块",
                url: "/WorkFlowSetting/FlowManage/EditWorkFlow?keyValue=" + rowobj.F_Id,
                width: "600px",
                height: "300px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                },
                
            });
        } else {
            $.modalAlert("请选中行数据！", "warning");
        }
    }

    function GetDictionaries(value, type) {
        if (type == "F_SiteType") {
            var strHtml = "";
            for (var i = 0; i < resultData.F_SiteType.length; i++) {
                if (value == resultData.F_SiteType[i].F_ItemCode) {
                    return resultData.F_SiteType[i].F_ItemName;
                }
            }
            return '';
        } else if (type == "F_ActivityCityId") {
            var strHtml = "";
            for (var i = 0; i < resultData.F_ActivityCityId.length; i++) {
                for (var j = 0; j < value.split(',').length; j++) {
                    if (j == value.split(',').length - 1) {
                        if (value.split(',')[j] == resultData.F_ActivityCityId[i].F_ItemCode) {
                            strHtml += resultData.F_ActivityCityId[i].F_ItemName;
                        }
                    } else {
                        if (value.split(',')[j] == resultData.F_ActivityCityId[i].F_ItemCode) {
                            strHtml += resultData.F_ActivityCityId[i].F_ItemName + ",";
                        }
                    }
                }
            }
            return strHtml;
        } else if (type == "F_ActivityType") {
            for (var i = 0; i < resultData.F_ActivityType.length; i++) {
                if (value == resultData.F_ActivityType[i].F_ItemCode) {
                    return resultData.F_ActivityType[i].F_ItemName;
                }
            }
            return '';
        }
    }

    function btn_onSearch() {
        var $gridList = $("#gridList");
        var queryJson = {
            F_DemandCash: $("#F_DemandCash").val(),
            F_ActivityCityId: $("#F_CityId").val(),
            F_ActivityType: $("#F_ActivityType").val(),
            F_ClientName: $("#F_ClientName").val(),
            F_ActivityStartDate: $("#F_ActivityStartDate").val(),
            F_CreatorTime: $("#F_CreatorDate").val(),
            F_State: $("#state_horizon a.active").attr('data-value')
        };
        $gridList.jqGrid('setGridParam', {
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }

    function btn_Add() {
        $.modalOpen({
            id: "editForm",
            title: "新建流程",
            url: "/WorkFlowSetting/FlowManage/EditWorkFlow",
            width: "500px",
            height: "200px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();

            }
        });

        //$.addTab({
        //    href: '/WorkFlowSetting/FlowManage/Details?',
        //    text: '流程管理-明细',
        //    id: '0000-0000-0000',
        //    index: 999
        //});
    }

    function btn_Update() {
        var rowobj = $("#gridList").jqGridRowValue();
        if (rowobj.F_Id) {
            $.modalOpen({
                id: "editForm",
                title: "编辑流程",
                url: "/ClientManager/DemandInfos/Form?F_Id=" + rowobj.F_Id + "&contactId=" + rowobj.contactId + "",
                width: "1200px",
                height: "800px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();

                }
            });
        } else {
            $.modalAlert("请选中行数据！", "warning");
        }
    }

    function btn_detail(id, type) {
        $.addTab({
            href: '/WorkFlowSetting/FlowManage/Details?keyValue=' + id,
            text: '流程管理-明细',
            id: id,
            index: 999
        });
    }
</script>
<div class="zdyPanel">
    <div class="zdyBar" style="float:left;white-space:nowrap;width:50%;">

    </div>
    <div class="zdyBar" style="float:right;white-space:nowrap;width:50%;padding-top:5px;">
        <div style="float:right;">
            <div class="btn-group">
                <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
            </div>
            <div class="btn-group">
                <a class="btn btn-primary" onclick="btn_Add()"><i class="fa fa-eraser">新建流程</i></a>
            </div>
            @*<div class="btn-group">
                    <a class="btn btn-primary" onclick="btn_Update()"><i class="fa fa-pencil-square-o">编辑需求</i></a>
                </div>*@
        </div>
    </div>
</div>
<div class="zdyGirdPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
